<?
class MailService
{
	static function Send($to, $subject, $body, $content_type='text/plain', $user_headers=Array(), $from_email='', $from_name='')
	{
		// заменяем спецсимволы
		if($content_type == 'text/plain')
		{
			$body = str_replace('&quot;','"',$body);
			$body = str_replace('&laquo;','"',$body);
			$body = str_replace('&raquo;','"',$body);
			$body = str_replace('&lsquo;',"'",$body);
			$body = str_replace('&lt;',"<",$body);
			$body = str_replace('&gt;',">",$body);
			$body = str_replace('&amp;',"&",$body);
		}
		
		if($from_email)
		{
			if($from_name)
			{
				$from = "=?windows-1251?B?" . base64_encode($from_name) . "?= <" . $from_email . ">";
			}
			else
			{
				$from = "=?windows-1251?B?" . base64_encode(MAIL_FROM_NAME) . "?= <" . $from_email . ">";
			}
		}
		else
		{
			$from = "=?windows-1251?B?" . base64_encode(MAIL_FROM_NAME) . "?= <" . MAIL_FROM . ">";
		}
		$subject = "=?windows-1251?b?" . base64_encode($subject) . "?=";
		
		$headers  = 'MIME-Version: 1.0' . MAIL_DELIMITER;
		$headers .= 'Content-type: '.$content_type.'; charset=windows-1251' . MAIL_DELIMITER;
		$headers .= 'From: '.$from.MAIL_DELIMITER;
		$headers .= 'Return-path: '.MAIL_FROM.MAIL_DELIMITER;
		foreach($user_headers as $user_header)
		{
			$headers .= $user_header.MAIL_DELIMITER;
		}
		
		if(HOST_TYPE!='local')
		{
			mail($to, $subject, $body, $headers);
		}
	}
}